<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class BaseInfoForm extends CMiniyunStatForm
{
	public $detect;
	public function  init(){
		$this->detect = array();		if(CCheckRequirements::checkGDFreeType()==false){
			$this->detect["gdError"]=true;
		}

	}

	public function getDiskTotalSpace() {
	    if (file_exists(BASE) == false) {
	        CUtils::MkDirs(BASE);
	    }
	    return @disk_total_space(BASE);
	}
	
	public function getDiskFreeSpace() {
	    if (file_exists(BASE) == false) {
            CUtils::MkDirs(BASE);
	    }
	    return @disk_free_space(BASE);
	}
	
	public function getDiskUsedInMiniyun() {
	    return $this->_directorySize();
	}
	
	public function chartPie(){
		$data = array();
		if(substr(PHP_OS,0,3)=="WIN"){ 			$letter = $this->_getPathLetter(BASE).":盘";		}else{
			$letter = "";
		}
	    if (file_exists(BASE) == false) {
	        CUtils::MkDirs(BASE);
	    }
		$space = @disk_free_space(BASE);
		array_push($data, array(Yii::app()->params['app']['name'].'使用', $this->_byteFormat($this->_directorySize())));
		array_push($data, array($letter."剩余空间", $this->_byteFormat($space)));
						$charOptions = array(
                    'theme' => 'gray',
                    'title' => array('text' => '空间使用情况'),
                    'tooltip' => array(
                    		   'formatter' => 'js:function(){ return \'<b>\'+ this.point.name +\'</b>: \'+ this.y +\' GB ，占\'+ForDight(this.percentage,1) +\' %\';}'
                    		   ),
                      'series' => array(
                    		   array(
                    'type' => 'pie',
                    'data' => $data,
                    		   ),
                    		   )
                    		   );
                    		   return $charOptions;

	}
	
	private function _byteFormat($size)
	{
		$size = $size/(1024*1024*1024);
		$size = round($size,2);
		if($size==0){
			$size =0.001;
		}
		return $size;
	}
	
	private function _getPathLetter($path){
		$list = explode(":",$path);
		return $list[0];
	}
	private function _directorySize() {
		$fileVersion = new FileVersion();
		$totalSize = $fileVersion->fileSum();
		if (!$totalSize) $totalSize = 0;
		return $totalSize;
	}
}